package com.lantosec.hmrp.modules.sysdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.modules.sysdata.entity.SysProcessNotify;
import com.lantosec.hmrp.modules.sysdata.mapper.SysProcessNotifyMapper;
import com.lantosec.hmrp.modules.sysdata.service.ISysProcessNotifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lantosec.hmrp.modules.sysdata.vo.SysProcessNotifyVO;
import org.springframework.stereotype.Service;
import org.springframework.context.annotation.Primary;
import lombok.extern.log4j.Log4j2;


/**
 * <p>
 * 流程知会表 服务实现类
 * </p>
 *
 * @author AutoCode
 * @since 2020-06-21
 */
@Service
@Primary
@Log4j2
public class SysProcessNotifyServiceImpl extends ServiceImpl<SysProcessNotifyMapper, SysProcessNotify> implements ISysProcessNotifyService {

    @Override
    public Page<SysProcessNotifyVO> queryListByUserId(PageVO<SysProcessNotifyVO> page, String userId, String notifyStatus) {
        return baseMapper.queryListByUserId(page, userId, notifyStatus);
    }

    @Override
    public boolean updateStatus(String userId, String processInstanceId) {
        SysProcessNotify notify = new SysProcessNotify();
        notify.setNotifyStatus("READED");
        int flag = baseMapper.update(notify, new QueryWrapper<SysProcessNotify>()
                .eq(String.valueOf(SysProcessNotify.ColName.notify_user_id), userId)
                .eq(String.valueOf(SysProcessNotify.ColName.pro_ins_id), processInstanceId)
                .eq(String.valueOf(SysProcessNotify.ColName.notify_status), "UNREAD"));
        return flag > 0;
    }

    @Override
    public long countByUserId(String userId){
        return baseMapper.selectCount(new QueryWrapper<SysProcessNotify>()
                .eq(SysProcessNotify.ColName.notify_user_id.toString(),userId)
                .eq(SysProcessNotify.ColName.notify_status.toString(),"UNREAD")
        );
    }
}
